//
//  myView.m
//  engineeringDrawing
//
//  Created by BJB0004 on 17/4/1.
//  Copyright © 2017年 HangzhouBaixiongtechnologyco.,LTD. All rights reserved.
//

#import "myView.h"



@interface myView(){

    float hangy;//最后一行与有多少
    
   double yu2;//先铺短板的余数
    
    double yu1; //先铺长板的余数
    BOOL isD;  //最后一块带电1
    BOOL isD2; //偶数行最后一块是否带电
    
    BOOL zisD;  //奇数2快短板 最后一块带电1
    BOOL zisD2; //偶数2块短板 行最后一块是否带电
    BOOL zisz1;
    int hang;
    int le1;
    int le2;
    
    double w;
    double h;
    int lw;
    int lh;
}



@end


@implementation myView




-(instancetype)initWithFrame:(CGRect)frame andWith:(double)with and:(double)height{
    self = [super initWithFrame:frame];
   self.backgroundColor = [UIColor whiteColor];
    w = (double)(with/10.0);
    h = (double)(height/10.0)+40 ;
    lw = with*10;
    lh =height *10;
    return self;
}

-(void)drawRect:(CGRect)rect{
    
    [super drawRect:rect];
    
    [self drawMyView];
}
-(void)drawDB{
    CGContextRef  ctx= UIGraphicsGetCurrentContext();
    //
      [[UIColor grayColor]set];
    //    //画空心的四边形
    CGContextStrokeRect(ctx, CGRectMake(0, 40, w, h-40));
    //
    
  
    //    //渲染
    
    CGContextFillPath(ctx);
    
     hang =lh/YBWITH;
    
     hangy = (lh%YBWITH)/100;
    
    for (int i =1; i<=hang+1; i++) {
        CGContextMoveToPoint(ctx, 0, BWITH*i+40);
        //设置终点
        CGContextAddLineToPoint(ctx, w,BWITH*i+40);
        CGContextSetLineWidth(ctx, 1);
        [[UIColor blackColor] setStroke];

        CGContextStrokePath(ctx);
        if (i%2==0) {//偶数行
//            NSLog(@"%d",i);
            CGContextMoveToPoint(ctx, HEIGHT, BWITH*(i-1)+40);
            //设置终点
            CGContextAddLineToPoint(ctx, HEIGHT,BWITH*i+40);
            
             CGContextSetLineWidth(ctx, 3);
            CGContextStrokePath(ctx);
            
            int num = (lw - YHEIGHT)/YLHEIGHT;
            
            
            yu2 =(double)((lw - YHEIGHT)%YLHEIGHT)*0.01;
            
            for (int j =1; j<=num+1; j++) {
                //设置起点
                CGContextMoveToPoint(ctx, HEIGHT+LHEIGHT*j, BWITH*(i-1)+40);
                //设置终点
                CGContextAddLineToPoint(ctx, HEIGHT+LHEIGHT*j,BWITH*i+40);
//                  [[UIColor orangeColor] setStroke];
                CGContextSetLineWidth(ctx, 3);
                CGContextStrokePath(ctx);
                if (i!=hang+1) {
                    
                
                if (j!=num+1){
                    
                
                if (hangy!=0) {
                    if (i!=hang+1) {
                        [self drawDianwith:i andj:j];
                    }
                    
                }else {
                 [self drawDianwith:i andj:j];
                  }
               }else{//最后一列
                   if(isD){
//                    [self drawDianwith:i andj:num+1];
                   }else{
                       if (yu2>=HEIGHT&&yu2<HEIGHT*2) {
                           if (i!=hang+1) {
//                                [self drawDanRBwith:i andj:num+1];//画密封线
                               
                             [self drawDianwith:i andj:num+1];
                           }

                       }else if(yu2<HEIGHT) {
                       if (i!=hang+1) {
                           [self drawDanwith:i andj:num+1];
                        }
                       }else if (yu2>=HEIGHT*2){//最后放两块短板
 #warning //偶数行 放两块短板
                           if (i!=hang+1) {
                         [self drawDianwith:i andj:num+1];
                           }
                       
                       
                       }
                   }
                
                
                }
                
        }
    }
            
#warning 添加zisD!=0
            
            UIColor * otherColor;
            if (num%2==0) {
               
                otherColor= [UIColor redColor];
            }else{
             
                otherColor =[UIColor blueColor];
            }

            if (yu2>=HEIGHT&&yu2<HEIGHT*2&&zisD!=1) {//最后为一块带电短板
                CGContextMoveToPoint(ctx, LHEIGHT*num+HEIGHT*2, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*num+HEIGHT*2,BWITH*i+40);
               [[UIColor blackColor] setStroke];
                
                CGContextStrokePath(ctx);
                
                UIColor * myColor;
                if (((int)(le1/2))%2) {
                    //蓝色
                    myColor = [UIColor redColor];
                }else{
                //红色
                    myColor =[UIColor blueColor];
                }
                //画点
                if (i!=hang+1) {
                
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+HEIGHT*2-12,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                                          [myColor set];
                
                
                //2.渲染
                CGContextFillPath(ctx);
                }
                [[UIColor blackColor] setStroke];
                
                isD2 = YES;
            }else if (yu2>=HEIGHT&&yu2<HEIGHT*2&&zisD==1){
            
            
               
                
                
                //2.渲染
                if (i!=hang+1) {
                    CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+HEIGHT*2-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                    //设置属性（颜色）
                    [otherColor set];
                    CGContextFillPath(ctx);
                }
                
            
            
            } else if(yu2<HEIGHT) {//最后为短板 不带电
                NSLog(@"偶数最后为短板 不带电");
                isD2 = NO;
                
            }else{
#warning //偶数行 放两块短板
                
                zisD2 = YES;
                
                CGContextMoveToPoint(ctx, LHEIGHT*num+HEIGHT*2, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*num+HEIGHT*2,BWITH*i+40);
                [[UIColor blackColor] setStroke];
                
                CGContextStrokePath(ctx);
                
                CGContextMoveToPoint(ctx, LHEIGHT*num+HEIGHT*3, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*num+HEIGHT*3,BWITH*i+40);
                [[UIColor blackColor] setStroke];
                
                CGContextStrokePath(ctx);

                //设点
                if (i!=hang+1) {
                    
                
                
                UIColor * mycolor ;
                UIColor * othreColor ;
                
                if (((int)(le1/2))%2) {
                    mycolor =[UIColor redColor];
                    othreColor = [UIColor blueColor];
                }else{
                    mycolor =[UIColor blueColor];
                    othreColor = [UIColor redColor];
                
                }
            
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+2*HEIGHT+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                [mycolor set];
                //2.渲染
                
                CGContextFillPath(ctx);
                
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+2*HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                [mycolor set];
                //2.渲染
                CGContextFillPath(ctx);
                    
                 
                    CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+3*HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                    //设置属性（颜色）
                    [othreColor set];
                    //2.渲染
                    
                    CGContextFillPath(ctx);
                    
                }
                
                
                
            }
            
            
//            
            
            
        }else{//奇数行

            int num = lw/YLHEIGHT;
             yu1 =(double)(lw %YLHEIGHT)*0.01;
            
            
            //                      int yu =(int)w %LHEIGHT;
           
            NSLog(@"%f",yu1);
            for (int j =1; j<=num; j++) {
                //设置起点
                CGContextMoveToPoint(ctx, LHEIGHT*j, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*j,BWITH*i+40);
//                [[UIColor greenColor] setStroke];
                CGContextSetLineWidth(ctx, 3);
                CGContextStrokePath(ctx);
                
                if(i!=hang+1){
                if (j!=num) {
                    
                
                
                if (hangy!=0) {
                    if (i!=hang+1) {
                        [self drawDianwith:i andj:j];
                    }
                    
                }else{
                    [self drawDianwith:i andj:j];
                }
                }else{//最后一列
                    if (yu1>=HEIGHT&&yu1<HEIGHT*2) {
                        
                         [self drawDianwith:i andj:num];
                        
                    }else if (yu1<HEIGHT){

                    if (i!=hang+1) {
                         [self drawDanwith:i andj:num];
                    }
                    }else{
#warning 奇数行最后一行为两块短板
                        zisD =YES;
                       [self drawDianwith:i andj:num];
                    
                    }
                
                
                
                }
                
                
            }
        }
            
            NSLog(@"%f====%f",yu1,HEIGHT);
            if (yu1>=HEIGHT&&yu1<HEIGHT*2) {//最后为一块带电短板
                CGContextMoveToPoint(ctx, LHEIGHT*(num)+HEIGHT, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*(num)+HEIGHT,BWITH*i+40);
//                               [[UIColor greenColor] setStroke];
                
                CGContextStrokePath(ctx);
                le1 = num*2+1;
                isD = YES;
            }else if (yu1<HEIGHT){//最后为短板 不带电
                NSLog(@"最后为短板 不带电");
                isD = NO;
                le1 = num*2;
            
            }else{
#warning 奇数最后为两块短板
                CGContextMoveToPoint(ctx, LHEIGHT*(num)+HEIGHT, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*(num)+HEIGHT,BWITH*i+40);
                //                               [[UIColor greenColor] setStroke];
                
                CGContextStrokePath(ctx);
                CGContextMoveToPoint(ctx, LHEIGHT*(num)+HEIGHT*2, BWITH*(i-1) +40);
                //设置终点
                CGContextAddLineToPoint(ctx, LHEIGHT*(num)+HEIGHT*2,BWITH*i+40);
                //                               [[UIColor greenColor] setStroke];
                
                CGContextStrokePath(ctx);
                
                //画点
                
                le1 = num*2+1;
                UIColor * myColor;
                UIColor * otherColor;
                if (num%2==0) {
                    myColor = [UIColor blueColor];
                    otherColor= [UIColor redColor];
                }else{
                myColor = [UIColor redColor];
                    otherColor =[UIColor blueColor];
                }
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+HEIGHT+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                [myColor set];
                //2.渲染
                
                CGContextFillPath(ctx);
                
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                [myColor set];
                //2.渲染
                CGContextFillPath(ctx);
                
                
                
                
                if (i!=hang+1) {
                    CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*num+HEIGHT*2-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                    //设置属性（颜色）
                    [otherColor set];
                    CGContextFillPath(ctx);
                }
                //2.渲染
                
              
                zisD = YES;
//              isD = YES;

                
            
            }
            
            
            
        }
        
    }


}
//画最后的两根单线
-(void)drawDanRBwith:(int)i andj:(int)j{

    CGContextRef  ctx= UIGraphicsGetCurrentContext();
    
    if (i%2==0){
        
            //画红点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT+8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            
            
       
            //画蓝点
            if (j==1) {
                CGContextAddEllipseInRect(ctx, CGRectMake(HEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                //                           [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
                
                
            }else{
                //画蓝点
                
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                //                           [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
            }
            
            
      
    }else{
        
        
        
            //画宏
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j+8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            
            
       
            //画蓝点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
        
        //
        
        
        
        
        
        
    }
    
    



}
//画最后单线

-(void)drawDanwith:(int)i andj:(int)j{
    CGContextRef  ctx= UIGraphicsGetCurrentContext();
    
    if (i%2==0){
        if (j%2==0) {
            //画红点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
        
            
        }else{
            //画蓝点
            if (j==1) {
                CGContextAddEllipseInRect(ctx, CGRectMake(HEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                //                           [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
               
                
            }else{
                //画蓝点
                
                CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
                //设置属性（颜色）
                //                           [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
                           }
            
            
        }
    }else{
        
        
        if (j%2==0) {
            //画宏
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
           
            
        }else{
            //画蓝点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
                   }
        //
        
        
        
        
        
        
    }



}

//画双排线
-(void)drawDianwith:(int)i andj:(int)j {
CGContextRef  ctx= UIGraphicsGetCurrentContext();
    
    if (i%2==0){//奇数行
    if (j%2==0) {
        //画红点
        
        CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
        //设置属性（颜色）
        //                           [[UIColor yellowColor]set];
        CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
        
        //2.渲染
        CGContextFillPath(ctx);
        CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
        //设置属性（颜色）
        //                           [[UIColor yellowColor]set];
        CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
        
        //2.渲染
        CGContextFillPath(ctx);
        
    }else{
        //画蓝点
        if (j==1) {
            CGContextAddEllipseInRect(ctx, CGRectMake(HEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            CGContextAddEllipseInRect(ctx, CGRectMake(HEIGHT*j+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            
        }else{
            //画蓝点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*(j-1)+HEIGHT+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            
        }
        
        
    }
    }else{
    
    
        if (j%2==0) {
            //画宏
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0,1);
            
            //2.渲染
            CGContextFillPath(ctx);
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            
        }else{
            //画蓝点
            
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j-8,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
            CGContextAddEllipseInRect(ctx, CGRectMake(LHEIGHT*j+4,BWITH/2-2+BWITH*(i-1)+40 , 4, 4));
            //设置属性（颜色）
            //                           [[UIColor yellowColor]set];
            CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
            
            //2.渲染
            CGContextFillPath(ctx);
        }
        //
        

    
    
    
    
    }
}
-(void)drawZDX{
   
     CGContextRef  ctx= UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ctx, 2);//设置线的宽度
    
    CGContextMoveToPoint(ctx, 4, 30);
    //设置终点
    CGContextAddLineToPoint(ctx, w,30);
    [[UIColor redColor] setStroke];
    CGContextStrokePath(ctx);
    //黄线
    CGContextMoveToPoint(ctx, 0, 20);
    //设置终点
    CGContextAddLineToPoint(ctx, w,20);
    [[UIColor blueColor] setStroke];
    CGContextStrokePath(ctx);





}

-(void)drawDRead{

    CGContextRef  ctx= UIGraphicsGetCurrentContext();
    //画红线
    CGContextSetLineWidth(ctx, 1);//设置线的宽度
    CGFloat lengths[] = {2,2};
    CGContextSetLineDash(ctx, 0, lengths,2);
    CGContextMoveToPoint(ctx, 4, 30);
    //设置终点
    CGContextAddLineToPoint(ctx, 4,hang*BWITH+40);
    [[UIColor redColor] setStroke];
    CGContextStrokePath(ctx);

    //创建红点密封线
    NSLog(@"####%d",hang);
    for (int i=0; i<hang; i++) {
        CGContextAddEllipseInRect(ctx, CGRectMake(2, 40+BWITH/2-2+i*BWITH, 4, 4));
        //设置属性（颜色）
        //       [[UIColor yellowColor]set];
        CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
        
        //2.渲染
        CGContextFillPath(ctx);

    }
    //创建双 红蓝线
  
    CGContextSetLineWidth(ctx, 1);//设置线的宽度
    int myhangj,myhango;
    if (hang%2==0) {
        myhangj = hang;
        myhango = hang - 1;
    }else{
        myhangj = hang -1;
        myhango =hang;
    }
   for (int i =1; i<=le1/2; i++) {
       if (i%2==1) {
           CGContextMoveToPoint(ctx, LHEIGHT*(i-1)+HEIGHT, 20);
           //设置终点
           CGContextAddLineToPoint(ctx, LHEIGHT*(i-1)+HEIGHT,myhangj*BWITH+40);
           
           [[UIColor blueColor] setStroke];
           CGContextStrokePath(ctx);
           
           if (i==le1/2&&isD!=1&&zisD!=1) {
               CGContextMoveToPoint(ctx, LHEIGHT*i-6, 20);
               //设置终点
               CGContextAddLineToPoint(ctx, LHEIGHT*i-6,myhango*BWITH+40);
           }else{
           CGContextMoveToPoint(ctx, LHEIGHT*i, 20);
           //设置终点
           CGContextAddLineToPoint(ctx, LHEIGHT*i,myhango*BWITH+40);
           }
           
           [[UIColor blueColor] setStroke];
           CGContextStrokePath(ctx);
       }else{
           CGContextMoveToPoint(ctx, LHEIGHT*(i-1)+HEIGHT, 30);
           //设置终点
           CGContextAddLineToPoint(ctx, LHEIGHT*(i-1)+HEIGHT,myhangj*BWITH+40);
           
           [[UIColor redColor] setStroke];
           CGContextStrokePath(ctx);
           
           if (i==le1/2&&isD!=1&&zisD!=1) {
               CGContextMoveToPoint(ctx, LHEIGHT*i-6, 30);
               //设置终点
               CGContextAddLineToPoint(ctx, LHEIGHT*i-6,myhango*BWITH+40);
           }else{
           
               CGContextMoveToPoint(ctx, LHEIGHT*i, 30);
               //设置终点
               CGContextAddLineToPoint(ctx, LHEIGHT*i,myhango*BWITH+40);
           }
           
           
           [[UIColor redColor] setStroke];
           CGContextStrokePath(ctx);
       
       
       }
       
    }
    
    if (zisD2) {
        int   i=le1/2;
        UIColor * mycolor ;
        UIColor * othreColor ;
        int y,y1;
        
        if (((int)(le1/2))%2) {
            mycolor =[UIColor redColor];
            othreColor = [UIColor blueColor];
            y=30;
            y1 =20;
        }else{
            mycolor =[UIColor blueColor];
            othreColor = [UIColor redColor];
            y=20;
            y1=30;
        }
        int myHang;
        if (hang%2==1) {
            myHang  = hang - 1;
        }else{
            myHang = hang;
        }

        CGContextMoveToPoint(ctx, LHEIGHT*i, y);
        //设置终点
        CGContextAddLineToPoint(ctx, LHEIGHT*i,myHang*BWITH+40);
        
        [mycolor setStroke];
        CGContextStrokePath(ctx);
        
        
        CGContextMoveToPoint(ctx, LHEIGHT*i+HEIGHT-6, y1);
        //设置终点
        CGContextAddLineToPoint(ctx, LHEIGHT*i+HEIGHT-6,myHang*BWITH+40);
        
        
        [othreColor setStroke];
        CGContextStrokePath(ctx);
        
  
        
        
    }
    if (zisD) {
        int   i=le1/2;
        
        UIColor * myClocr;
        UIColor * otherClocr;
        int y,y1;
        if (i%2==0) {
            myClocr =[UIColor blueColor];
            otherClocr =[UIColor redColor];
            y=20;
            y1=30;
        }else{
            myClocr =[UIColor redColor];
            otherClocr =[UIColor blueColor];
            y=30;
            y1 =20;
        }
        
            CGContextMoveToPoint(ctx, LHEIGHT*i+HEIGHT, y);
            //设置终点
            CGContextAddLineToPoint(ctx, LHEIGHT*i+HEIGHT,hang*BWITH+40);
            
            [myClocr setStroke];
            CGContextStrokePath(ctx);
            
       
            CGContextMoveToPoint(ctx, LHEIGHT*i+HEIGHT*2-6, y1);
            //设置终点
            CGContextAddLineToPoint(ctx, LHEIGHT*i+HEIGHT*2-6,hang*BWITH+40);
        
            
            [otherClocr setStroke];
            CGContextStrokePath(ctx);
            
            
            
       

        
        
    }
    if (isD2&&zisD!=1) {
        int   i=le1/2;
        if (i%2==0) {
            CGContextMoveToPoint(ctx, LHEIGHT*i-12, 20);
            //设置终点
            CGContextAddLineToPoint(ctx, LHEIGHT*i-12,myhango*BWITH+40);
            
            [[UIColor blueColor] setStroke];
            CGContextStrokePath(ctx);
        
        }else{
            CGContextMoveToPoint(ctx, LHEIGHT*i-12, 30);
            //设置终点
            CGContextAddLineToPoint(ctx, LHEIGHT*i-12,myhangj*BWITH+40);
            
            [[UIColor redColor] setStroke];
            CGContextStrokePath(ctx);
            
            
            
        }

    }
 
    if (isD) {//封线
        if ((int)(le1/2)%2==0) {
            CGContextMoveToPoint(ctx, ((int)(le1/2))*LHEIGHT+HEIGHT-4, 20);
            //设置终点
            CGContextAddLineToPoint(ctx, ((int)(le1/2))*LHEIGHT+HEIGHT-4,hang*BWITH+40);
            [[UIColor blueColor] setStroke];
            CGContextStrokePath(ctx);
            
            
            for (int i=0; i<hang; i++) {
                CGContextAddEllipseInRect(ctx, CGRectMake(((int)(le1/2))*LHEIGHT+HEIGHT-6, 40+BWITH/2-2+i*BWITH, 4, 4));
                //设置属性（颜色）
                //       [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
                
            }

        }else{
        
            CGContextMoveToPoint(ctx, ((int)(le1/2))*LHEIGHT+HEIGHT-4, 30);
            //设置终点
            CGContextAddLineToPoint(ctx, ((int)(le1/2))*LHEIGHT+HEIGHT-4,hang*BWITH+40);
            [[UIColor redColor] setStroke];
            CGContextStrokePath(ctx);
            
            
            for (int i=0; i<hang; i++) {
                CGContextAddEllipseInRect(ctx, CGRectMake(((int)(le1/2))*LHEIGHT+HEIGHT-6, 40+BWITH/2-2+i*BWITH, 4, 4));
                //设置属性（颜色）
                //       [[UIColor yellowColor]set];
                CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
                
                //2.渲染
                CGContextFillPath(ctx);
                
            }

        
        
        }
        
        
    }

   
    
    

}
-(void)drawMyView{

    //地板
    [self drawDB];
    //主线
    [self drawZDX];
    //红蓝双线
   [self drawDRead];
    
    
    
    
   


 
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
